﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Core.Interface;
using System.Configuration;
using PServiceBus.Core.Runtime;
using Phoenix.ReflectionExtensions;
using PServiceBus.Core.Logger;
using PServiceBus.Core.Configuration;
using PServiceBus.Core.Runtime.Configuration;

namespace PServiceBus.Core.Manager {
    public class SubscriptionManagerManager {
        static List<ISubscriptionManager> _managers;
        public static List<ISubscriptionManager> Managers {
            get {
                if (_managers == null) {
                    _managers = new List<ISubscriptionManager>();
                    foreach (var manager in ConfigurationProvider.SubscriptionConfigs) {
                        MethodHelper.TryLog(() =>
                        {
                            var subscriptionManager = DynamicBroker.Broker[manager.Type].New() as ISubscriptionManager;
                            subscriptionManager.Address = manager.Address;
                            _managers.Add(subscriptionManager);
                        });
                    }
                }
                return _managers;
            }
        }
    }
}
